package com.example.testluckyroulette.bean;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.target.CustomTarget;
import com.bumptech.glide.request.transition.Transition;
import com.example.testluckyroulette.R;

import java.io.Serializable;

/**
 * Create Time:2020/9/10
 * Author: Lindanrong
 * Description:
 */
public  class LuckyPersonBean  implements Serializable {
    public int id;
    public float mCenterAngle;
    public String name;
    public String avatar;
    public int color;
    public Bitmap avatarBitmap;

    public void setAvatar(final Context context, final String avater, int resourceId, final BitmapNoStatusCallBack bitmapCallBack) {
        this.avatar = avater;
        Glide.with(context).asBitmap()
                .optionalFitCenter()
                .optionalCenterCrop()
                .load(!TextUtils.isEmpty(avater)?avater:resourceId).into(new CustomTarget<Bitmap>() {
            @Override
            public void onLoadFailed(@Nullable Drawable errorDrawable) {
                avatarBitmap =  BitmapFactory.decodeResource(context.getResources(), R.mipmap.default_avatar);
                bitmapCallBack.onResult();
            }


            @Override
            public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
                avatarBitmap = resource;
                bitmapCallBack.onResult();
            }

            @Override
            public void onLoadCleared(@Nullable Drawable placeholder) {

            }
        });
    }
}
